package cn.huiyunche.base.service.interfaces.impl;

import cn.huiyunche.base.service.form.SOrderComplainForm;
import cn.huiyunche.base.service.interfaces.SOrderComplainService;
import cn.huiyunche.base.service.interfaces.UserService;
import cn.huiyunche.base.service.mappers.SOrderComplaintsMapper;
import cn.huiyunche.base.service.model.SOrderComplaints;
import cn.huiyunche.base.service.vo.UserShowVo;
import cn.huiyunche.tools.basic.exceptions.BusinessException;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by LYN on 9/11/16.
 */
@Service
public class SOrderComplainServiceImpl implements SOrderComplainService {

    @Autowired
    SOrderComplaintsMapper sOrderComplaintsMapper;

    @Autowired
    UserService userService;

    @Override
    public boolean create(SOrderComplainForm sOrderComplainForm) throws Exception {
        SOrderComplaints sOrderComplaints = new SOrderComplaints();
        BeanUtils.copyProperties(sOrderComplainForm, sOrderComplaints);

        UserShowVo userVo = userService.getCurrentUser();
        if (null == userVo) {
            throw new BusinessException("未找到当前用户，请重新登录!");
        }
        sOrderComplaints.setUserId(userVo.getId());
        //TODO 敏感词过滤
        sOrderComplaintsMapper.insertSelective(sOrderComplaints);
        return true;
    }
}
